<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../../assets/css/base.css">
    <style>
        .bottom-bar{
            position: static;
            left: 0px;
            top: 0px;
            width: 100%;
            height: 60px;
            border-top: 1px solid #ccc;
            box-shadow: 0 0 8px #666;
            display: flex;
            flex-flow: row nowrap;
            align-items: center;
        }
        .bottom-bar > div{
            flex-grow: 1;
            text-align: center;
            cursor: pointer;
        }
        .bottom-bar > div:hover{
            color: orangered;
        }
    </style>
</head>
<body>
    <div id="app">
        <div class="bottom-bar">
            <div @click="changePage('HomePage')">首页</div>
            <div @click="changePage('ListPage')">列表</div>
            <div @click="changePage('CartPage')">购物车</div>
            <div @click="changePage('AboutPage')">关于我</div>
        </div>
        <pre v-pre class="note">
        内置全局组件:无需加载直接可用的的组件【vue环境已经提供的全局组件】

        动态组件技术：
            + 一个整合了创建和销毁组件逻辑操作的组件切换的功能标签
            + 通过必传递属性 is 取值动态仓库变量完成响应式的组件切换操作
        
        项目设计方案:SPA【single page web application】
            + 提供给浏览器的主容器页面只有一个，其它页面内容以JS方式动态渲染
            + 页面切换可以减少网络请求次数，从而提示页面的渲染速度
        </pre>
        <!-- <home-page v-if="page=='HomePage'"></home-page>
        <list-page v-if="page=='ListPage'"></list-page>
        <cart-page v-if="page=='CartPage'"></cart-page>
        <about-page v-if="page=='AboutPage'"></about-page> -->

        <!-- <component is="ListPage"></component> -->
        <hr>
        <component v-bind:is="page"></component>
        <hr>
    </div>
    <script type="module">
        import { createApp } from "../../assets/vue3/vue.esm-browser.js";
        import HomePage from "./views/HomePage.js"
        import ListPage from "./views/ListPage.js"
        import CartPage from "./views/CartPage.js"
        import AboutPage from "./views/AboutPage.js"

        createApp({
            components: {
                HomePage,ListPage,CartPage,AboutPage
            },
            data(){
                return {
                    page:"HomePage"
                }
            },
            methods: {
                changePage(page) {
                    this.page = page;
                    location.hash = page;
                }
            },
            created () {
                // console.log(location.hash);
                let page = location.hash.replace(/^#/,"")
                if(page!=""){
                    this.page = page
                }
            },
        }).mount("#app");
    </script>
</body>
</html>